/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mvc.login;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


/**
 *
 * @author Admin
 */
public class UserBean implements Serializable{
    public UserBean()
    {
        
    }
    public boolean checkLogin(String username,String password)
    {
           Connection conn = null;
    try{
        String userConn ="root";
        String passConn = "tyty2629";
        String url = "jdbc:mysql://127.0.0.1:3306/mangementscore";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        conn = DriverManager.getConnection(url, userConn, passConn);
        System.out.println("Da ket noi CSDL");
        String sql = "Select * from administrator where username =? and password =?";
        PreparedStatement stm = conn.prepareStatement(sql);
        stm.setString(1, username.toLowerCase());
        stm.setString(2, password);
        ResultSet rs = stm.executeQuery();  
        boolean result = rs.next();   //neu co ban ghi thi result = true
        rs.close();
        stm.close();
        conn.close();
        if(result)
        {
            return true;    // tra ve true neu select ra dung gia tri da nhap vao
        }
        
        

    }
    catch(Exception e ){
         System.out.println(e.toString());
            
    }
    return false;
    }
}
